package edu.gmu.projects.fireresponder.gui;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import android.app.ListActivity;
import android.os.Bundle;
import android.text.format.DateFormat;
import android.widget.ArrayAdapter;
import edu.gmu.projects.fireresponder.R;
import edu.gmu.projects.fireresponder.environment.Location;

public class AssetDialogMessagesTab extends ListActivity {
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.messages_list);

		Bundle bundle = getIntent().getExtras();

		double lat = bundle.getDouble(SituationMap.LAT);
		double lng = bundle.getDouble(SituationMap.LNG);
		Location location = new Location(lat, lng);

		List<String> messages = new ArrayList<String>();

		Collections.sort(SituationMap.getResponderMessages(), Collections
				.reverseOrder());

		for (ResponderMessage m : SituationMap.getResponderMessages()) {
			if (m.getLocation().equals(location)) {
				String timeStamp = (String) DateFormat.format("MMM dd, yyyy h:mmaa", m.getTimeStamp());

				String message = String.format("%s\n%s\n\n%s", m.getSenderId(),
						timeStamp, m.getMessage());

				messages.add(message);
			}
		}

		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, messages);

		setListAdapter(adapter);
	}
}